//获取应用实例
var app = getApp();
var util = require('../../util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:true,
    page:1,//当前页码
    totalpage:100,//总页码
    pallet:[],//定义货盘列表
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getData();
  },
  //获得货盘
  getData: function (res) {
    var that = this;
    if (that.data.page <= that.data.totalpage){
      app.getLoginSession(function (session) {
        wx.request({
          url: app.api + '/wx_log_test/cargo/list',
          data: {
            token: session,
            page: that.data.page,
            perpage: 10
          },
          success: function (e) {
            console.log(e);
            var res = e.data;
            if (res.msg == "OK") {
              
              that.setData({
                pallet: that.data.pallet.concat(that.deallist(res.data.content)),
                loading: false,
                totalpage: res.data.totalPages
              })
              if (that.data.page == that.data.totalpage) {
                that.setData({
                  loadTips: '暂无更多数据',
                  page:that.data.page+1
                })
              }else{
                that.setData({
                  page: that.data.page + 1
                })
              }
            } else {
              that.setData({
                loading: false,
                errorTips: "接口请求失败" + e.statusCode
              })
            }
          },
          fail: function (e) {
            that.setData({
              loading: true,
              errorTips: "接口请求失败" + e.statusCode
            })
          }
        })
      })
    }
  },
  // 上拉触底
  lower: function () {
    var that = this;
    that.getData();
  },
  call: function (res) {
    wx.makePhoneCall({
      phoneNumber: res.currentTarget.dataset.num //仅为示例，并非真实的电话号码
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  deallist(list) {
    if (list && Array.isArray(list)) {
      list.forEach((item) => {
        console.log(item);
        item.send_date1 = util.formatDate(new Date(item.send_date1), 'YYYY-MM-dd')
      })
      return list
    }
  }
})